package uvt.gui.mainframe.object.menuitem;

import java.awt.BorderLayout;

import javax.swing.JCheckBoxMenuItem;
import javax.swing.JPanel;

import uvt.gui.mainframe.CreateTransportationNetworkPanel;
import uvt.gui.mainframe.object.command.Command;
import uvt.gui.mainframe.searchroute.SearchRoutePanel;

public class AddMapElementsMenuItem extends JCheckBoxMenuItem implements Command {

	private JPanel parentPanel;
	private SearchRoutePanel searchRoutePanel;
	private CreateTransportationNetworkPanel transportationNetworkPanel;
	
	public AddMapElementsMenuItem(JPanel pp,SearchRoutePanel srp,
			                      CreateTransportationNetworkPanel ctnp) {
		super("Add map elements",false);
		this.parentPanel = pp;
		this.searchRoutePanel = srp;
		this.transportationNetworkPanel = ctnp;
	}
	
	public void execute() {
		if(this.isSelected()) {
			parentPanel.remove(searchRoutePanel);
			searchRoutePanel.cleanPanel();
			searchRoutePanel.cleanMap();
			parentPanel.add(transportationNetworkPanel,BorderLayout.NORTH);			
			parentPanel.revalidate();
		} else {
			parentPanel.remove(transportationNetworkPanel);
			transportationNetworkPanel.cleanPanel();
			searchRoutePanel.cleanMap();
			parentPanel.add(searchRoutePanel,BorderLayout.NORTH);
			parentPanel.revalidate();
		}
	} 
	
}
